package com.houweishi.module.copy.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.houweishi.common.constant.Constants;
import com.houweishi.common.constant.HttpStatus;
import com.houweishi.common.core.domain.AjaxResult;
import com.houweishi.common.core.domain.model.LoginUser;
import com.houweishi.common.utils.DateUtils;
import com.houweishi.common.utils.SecurityUtils;
import com.houweishi.module.adjustment.mapper.OaAdjustmentMapper;
import com.houweishi.module.contract.mapper.OaContractApprovalMapper;
import com.houweishi.module.currency.mapper.OaCurrencyMapper;
import com.houweishi.module.evection.mapper.OaEvectionMapper;
import com.houweishi.module.leave.mapper.OaLeaveMapper;
import com.houweishi.module.reimburse.mapper.OaReimburseMapper;
import com.houweishi.module.train.mapper.OaTrainMapper;
import org.springframework.stereotype.Service;
import com.houweishi.module.copy.mapper.BizCopyMapper;
import com.houweishi.module.copy.domain.BizCopy;
import com.houweishi.module.copy.service.IBizCopyService;


import javax.annotation.Resource;

/**
 * 审批抄送管理Service业务层处理
 * 
 * @author houweishi
 * @date 2023-02-21
 */
@Service
public class BizCopyServiceImpl implements IBizCopyService 
{
//    @Autowired
    @Resource
    private BizCopyMapper bizCopyMapper;

    @Resource
    private OaLeaveMapper oaLeaveMapper;
    @Resource
    private OaAdjustmentMapper oaAdjustmentMapper;
    @Resource
    private OaContractApprovalMapper oaContractApprovalMapper;
    @Resource
    private OaEvectionMapper oaEvectionMapper;
    @Resource
    private OaReimburseMapper oaReimburseMapper;
    @Resource
    private OaTrainMapper oaTrainMapper;
    @Resource
    private OaCurrencyMapper oaCurrencyMapper;

    /**
     * 查询审批抄送管理
     * 
     * @param id 审批抄送管理主键
     * @return 审批抄送管理
     */
    @Override
    public BizCopy selectBizCopyById(Long id)
    {
        return bizCopyMapper.selectBizCopyById(id);
    }

    /**
     * 查询审批抄送管理列表
     * 
     * @param bizCopy 审批抄送管理
     * @return 审批抄送管理
     */
    @Override
    public List<BizCopy> selectBizCopyList(BizCopy bizCopy)
    {
        return bizCopyMapper.selectBizCopyList(bizCopy);
    }

    /**
     * 查询审批抄送管理列表
     *
     * @param fieldsNames 审批抄送管理
     * @return 审批抄送管理
     */
    @Override
    public List<BizCopy> selectBizCopyList2(String fieldsNames)
    {
        return bizCopyMapper.selectBizCopyList2(fieldsNames);
    }

    /**
     * 新增审批抄送管理
     * 
     * @param bizCopy 审批抄送管理
     * @return 结果
     */
    @Override
    public int insertBizCopy(BizCopy bizCopy)
    {
        bizCopy.setCreateTime(DateUtils.getNowDate());
        return bizCopyMapper.insertBizCopy(bizCopy);
    }

    /**
     * 修改审批抄送记录管理
     * 
     * @param bizCopy 审批抄送管理
     * @return 结果
     */
    @Override
    public int updateBizCopy(BizCopy bizCopy)
    {
        bizCopy.setUpdateTime(DateUtils.getNowDate());
        int result = bizCopyMapper.updateBizCopy(bizCopy);
        return result;
    }

    /**
     * 修改抄送状态根据流水单号
     * @param bizCopy
     * @return
     */
    @Override
    public AjaxResult updateBizCopyBySerialNum(BizCopy bizCopy) {
        //获取当前人
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (loginUser==null){
            return new AjaxResult(HttpStatus.UNAUTHORIZED,"请先登录");
        }
        bizCopy.setUpdateBy(loginUser.getUsername());
        bizCopy.setCopyerStatus(Constants.DATA_VALID_STATE);
        bizCopy.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
        if(bizCopyMapper.updateBizCopyBySerialNum(bizCopy)<1){
            return new AjaxResult(HttpStatus.ERROR,"修改失败");
        }
        return AjaxResult.success();
    }

    /**
     * 批量删除审批抄送管理
     * 
     * @param ids 需要删除的审批抄送管理主键
     * @return 结果
     */
    @Override
    public int deleteBizCopyByIds(Long[] ids)
    {
        return bizCopyMapper.deleteBizCopyByIds(ids);
    }

    /**
     * 删除审批抄送管理信息
     * 
     * @param id 审批抄送管理主键
     * @return 结果
     */
    @Override
    public int deleteBizCopyById(Long id)
    {
        return bizCopyMapper.deleteBizCopyById(id);
    }
}
